home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / interp / perl5.005.tar.gz / perl5.005.tar / perl5.005 / t / pragma / strict-refs < prev    next >
Text File  |  1998-07-19  |  5KB  |  296 lines

  1. Check strict refs functionality
  2.  
  3. __END__
  4.  
  5. # no strict, should build & run ok.
  6. my $fred ;
  7. $b = "fred" ;
  8. $a = $$b ;
  9. $c = ${"def"} ;
  10. $c = @{"def"} ;
  11. $c = %{"def"} ;
  12. $c = *{"def"} ;
  13. $c = \&{"def"} ;
  14. $c = def->[0];
  15. $c = def->{xyz};
  16. EXPECT
  17.  
  18. ########
  19.  
  20. # strict refs - error
  21. use strict ;
  22. my $fred ;
  23. my $a = ${"fred"} ;
  24. EXPECT
  25. Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 5.
  26. ########
  27.  
  28. # strict refs - error
  29. use strict 'refs' ;
  30. my $fred ;
  31. my $a = ${"fred"} ;
  32. EXPECT
  33. Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 5.
  34. ########
  35.  
  36. # strict refs - error
  37. use strict 'refs' ;
  38. my $fred ;
  39. my $b = "fred" ;
  40. my $a = $$b ;
  41. EXPECT
  42. Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 6.
  43. ########
  44.  
  45. # strict refs - error
  46. use strict 'refs' ;
  47. my $b ;
  48. my $a = $$b ;
  49. EXPECT
  50. Can't use an undefined value as a SCALAR reference at - line 5.
  51. ########
  52.  
  53. # strict refs - error
  54. use strict 'refs' ;
  55. my $b ;
  56. my $a = @$b ;
  57. EXPECT
  58. Can't use an undefined value as an ARRAY reference at - line 5.
  59. ########
  60.  
  61. # strict refs - error
  62. use strict 'refs' ;
  63. my $b ;
  64. my $a = %$b ;
  65. EXPECT
  66. Can't use an undefined value as a HASH reference at - line 5.
  67. ########
  68.  
  69. # strict refs - error
  70. use strict 'refs' ;
  71. my $b ;
  72. my $a = *$b ;
  73. EXPECT
  74. Can't use an undefined value as a symbol reference at - line 5.
  75. ########
  76.  
  77. # strict refs - error
  78. use strict 'refs' ;
  79. my $a = fred->[0] ;
  80. EXPECT
  81. Can't use bareword ("fred") as an ARRAY ref while "strict refs" in use at - line 4.
  82. ########
  83.  
  84. # strict refs - error
  85. use strict 'refs' ;
  86. my $a = fred->{barney} ;
  87. EXPECT
  88. Can't use bareword ("fred") as a HASH ref while "strict refs" in use at - line 4.
  89. ########
  90.  
  91. # strict refs - no error
  92. use strict ;
  93. no strict 'refs' ;
  94. my $fred ;
  95. my $b = "fred" ;
  96. my $a = $$b ;
  97. use strict 'refs' ;
  98. EXPECT
  99.  
  100. ########
  101.  
  102. # strict refs - no error
  103. use strict qw(subs vars) ;
  104. my $fred ;
  105. my $b = "fred" ;
  106. my $a = $$b ;
  107. use strict 'refs' ;
  108. EXPECT
  109.  
  110. ########
  111.  
  112. # strict refs - no error
  113. my $fred ;
  114. my $b = "fred" ;
  115. my $a = $$b ;
  116. use strict 'refs' ;
  117. EXPECT
  118.  
  119. ########
  120.  
  121. # strict refs - no error
  122. use strict 'refs' ;
  123. my $fred ;
  124. my $b = \$fred ;
  125. my $a = $$b ;
  126. EXPECT
  127.  
  128. ########
  129.  
  130. # Check runtime scope of strict refs pragma
  131. use strict 'refs';
  132. my $fred ;
  133. my $b = "fred" ;
  134. {
  135.     no strict ;
  136.     my $a = $$b ;
  137. }
  138. my $a = $$b ;
  139. EXPECT
  140. Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 10.
  141. ########
  142.  
  143. # Check runtime scope of strict refs pragma
  144. no strict ;
  145. my $fred ;
  146. my $b = "fred" ;
  147. {
  148.     use strict 'refs' ;
  149.     my $a = $$b ;
  150. }
  151. my $a = $$b ;
  152. EXPECT
  153. Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8.
  154. ########
  155.  
  156. # Check runtime scope of strict refs pragma
  157. no strict ;
  158. my $fred ;
  159. my $b = "fred" ;
  160. {
  161.     use strict 'refs' ;
  162.     $a = sub { my $c = $$b ; }
  163. }
  164. &$a ;
  165. EXPECT
  166. Can't use string ("fred") as a SCALAR ref while "strict refs" in use at - line 8.
  167. ########
  168.  
  169.  
  170. --FILE-- abc
  171. my $a = ${"Fred"} ;
  172. 1;
  173. --FILE-- 
  174. use strict 'refs' ;
  175. require "./abc";
  176. EXPECT
  177.  
  178. ########
  179.  
  180. --FILE-- abc
  181. use strict 'refs' ;
  182. 1;
  183. --FILE-- 
  184. require "./abc";
  185. my $a = ${"Fred"} ;
  186. EXPECT
  187.  
  188. ########
  189.  
  190. --FILE-- abc
  191. use strict 'refs' ;
  192. my $a = ${"Fred"} ;
  193. 1;
  194. --FILE-- 
  195. ${"Fred"} ;
  196. require "./abc";
  197. EXPECT
  198. Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at ./abc line 2.
  199. ########
  200.  
  201. --FILE-- abc.pm
  202. use strict 'refs' ;
  203. my $a = ${"Fred"} ;
  204. 1;
  205. --FILE-- 
  206. my $a = ${"Fred"} ;
  207. use abc;
  208. EXPECT
  209. Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at abc.pm line 2.
  210. BEGIN failed--compilation aborted at - line 2.
  211. ########
  212.  
  213. # Check scope of pragma with eval
  214. no strict ;
  215. eval {
  216.     my $a = ${"Fred"} ;
  217. };
  218. print STDERR $@ ;
  219. my $a = ${"Fred"} ;
  220. EXPECT
  221.  
  222. ########
  223.  
  224. # Check scope of pragma with eval
  225. no strict ;
  226. eval {
  227.     use strict 'refs' ;
  228.     my $a = ${"Fred"} ;
  229. };
  230. print STDERR $@ ;
  231. my $a = ${"Fred"} ;
  232. EXPECT
  233. Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 6.
  234. ########
  235.  
  236. # Check scope of pragma with eval
  237. use strict 'refs' ;
  238. eval {
  239.     my $a = ${"Fred"} ;
  240. };
  241. print STDERR $@ ;
  242. EXPECT
  243. Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 5.
  244. ########
  245.  
  246. # Check scope of pragma with eval
  247. use strict 'refs' ;
  248. eval {
  249.     no strict ;
  250.     my $a = ${"Fred"} ;
  251. };
  252. print STDERR $@ ;
  253. my $a = ${"Fred"} ;
  254. EXPECT
  255. Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 9.
  256. ########
  257.  
  258. # Check scope of pragma with eval
  259. no strict ;
  260. eval '
  261.     my $a = ${"Fred"} ;
  262. '; print STDERR $@ ;
  263. my $a = ${"Fred"} ;
  264. EXPECT
  265.  
  266. ########
  267.  
  268. # Check scope of pragma with eval
  269. no strict ;
  270. eval q[ 
  271.     use strict 'refs' ;
  272.     my $a = ${"Fred"} ;
  273. ]; print STDERR $@;
  274. EXPECT
  275. Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 3.
  276. ########
  277.  
  278. # Check scope of pragma with eval
  279. use strict 'refs' ;
  280. eval '
  281.     my $a = ${"Fred"} ;
  282. '; print STDERR $@ ;
  283. EXPECT
  284. Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at (eval 1) line 2.
  285. ########
  286.  
  287. # Check scope of pragma with eval
  288. use strict 'refs' ;
  289. eval '
  290.     no strict ;
  291.     my $a = ${"Fred"} ;
  292. '; print STDERR $@;
  293. my $a = ${"Fred"} ;
  294. EXPECT
  295. Can't use string ("Fred") as a SCALAR ref while "strict refs" in use at - line 8.
  296.